from meiduo.settings import dev
from django.core.mail import send_mail
from celery_tasks.main import celery_app
from django.core import signing
from celery_tasks import config


@celery_app.task(bin=True, name='EMAIL')
def take_email(user_id, user_email):
    data = {'user_id': user_id, 'email': user_email}
    value = signing.dumps(data)
    verify_url = config.email_verify_url + '?value=' + value
    to_email = user_email
    subject = '美多商城激活'
    html_message = "<p><a href='%s'>%s</a></p>" % (verify_url, verify_url)
    print(subject, dev.EMAIL_FROM, to_email, html_message)
    a = send_mail(subject, "", dev.EMAIL_FROM, [to_email], html_message=html_message)
    return a
